package com.jizhi.controller;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jizhi.entity.Drugdictionary;
import com.jizhi.service.DrugdictionaryService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王书豪
 * @since 2020-11-17
 */
@RestController
@RequestMapping("/drugdictionary")
public class DrugdictionaryController {
    @Resource
    private DrugdictionaryService drugdictionaryService;
    @ApiOperation(value = "分页查询全部药品清单表信息", notes = "根据在第几页的页码current来分页查询全部药品清单表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "在第几页的页码", required = true, dataType = "Integer",paramType = "path"),
            @ApiImplicitParam(name = "drugName", value = "模糊查询的drugName值", required = true, dataType = "String",paramType = "path")
    })

    @GetMapping("/filuPageAll/{current}/{drugName}")
    @ResponseBody
    public Object filuPageAll(@PathVariable("current")Integer current,@PathVariable("drugName")String drugName){
        Page<Object> page = new Page<>(current,2);
        List<Drugdictionary> doctorList = drugdictionaryService.filuPageAll(page,drugName);
        String json= JSONArray.toJSONString(doctorList);//转成json字符串
        return json;
    }
    @ApiOperation(value = "根据id查询药品清单信息", notes = "根据id查询药品清单信息")
    @ApiImplicitParam(name = "id", value = "药品清单的ID", required = true, dataType = "Integer",paramType = "path")
    @ResponseBody
    @GetMapping("/filuById/{id}")
    public Object filuById(@PathVariable("id")Integer id){
        Drugdictionary drugdictionary= drugdictionaryService.filuById(id);
        if (null!=drugdictionary){
            return drugdictionary;
        }else {
            return "查询失败";
        }
    }
}

